# -*- coding: utf-8 -*-
"""
Created on Mon May 24 15:00:57 2021

@author: Jerry Peng
"""

import os
def getfile_size(f_path):
    if not check_file(f_path):
        
        size=0
        for root,dirs,file in os.walk(f_path):
            size += sum(os.path.getsize(os.path.join(root,name)) for name in file)
        return size
    else:
        return os.path.getsize(f_path)

def check_file(f_path):
    return os.path.isfile(f_path)


    

dirct = r'C:\Users\Jerry Peng\Desktop\培训学习'
s=getfile_size(dirct)
if check_file(dirct):
    print("该文件的大小是：%.2f字节" %s)
else:
    print("该文件夹的大小是：%.2f字节" %s)
